﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.RDS
{
    [CPPEI.WebApi.AuthPostAction("RDS", "CreateDataSource", "1.0")]
    public class CreateDataSourceAction : BaseAction<CreateDataSourceParams, CreateDataSourceResult>
    {
        protected override ActionResult<CreateDataSourceResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            CreateDataSourceParams opParams)
        {

            Guid categoryId = new Guid("{9AB56520-B2A9-4BCA-B85E-E19A3764B26D}");
            Guid typeId = new Guid("{09F75019-CBEA-401A-80A4-47502C057302}");

            SER.DtSerService dtSerService = new SER.DtSerService();
            ServiceResult serResult = dtSerService.CreateDtSource(context.UserId, opParams.DataServiceId,
                opParams.Name,
                opParams.Value,
                0,
                null,
                null,
                null);
            if(serResult.IsSuccess)
            {
                CreateDataSourceResult result = new CreateDataSourceResult();
                return new ActionResult<CreateDataSourceResult>(result);
            }
            else
            {
                return new ActionResult<CreateDataSourceResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class CreateDataSourceParams
    {
        [Parameter]
        public string Name { get; set; }


        [Parameter]
        public Guid DataServiceId { get; set; }

        /// <summary>
        /// 通过EnumerateTable获取Table信息，然后将选中的Table的Id作为Value
        /// </summary>
        public string Value { get; set; }
    }

    public class CreateDataSourceResult
    {
    }
}
